package xp.ass.imitate.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import xp.ass.imitate.core.EnhanceEnum;

import java.util.Arrays;

/**
 * @author chent3
 * @date 2024/7/25
 */
@AllArgsConstructor
@Getter
public enum TypeMappingEnum implements EnhanceEnum<Class<?>> {

    INT(Integer.class, 1),
    BYTE(Byte.class, 2),
    STRING(String.class, 3),
    LONG(Long.class, 4);

    private final Class<?> code;

    private final Integer typeFlag;


    public static Integer getTypeFlag(Class<?> clazz) {
        return Arrays.stream(TypeMappingEnum.values())
                .filter(e -> e.eq(clazz))
                .findFirst()
                .map(TypeMappingEnum::getTypeFlag)
                .orElseThrow(IllegalArgumentException::new);
    }


}
